package com.joinway.${mapperModuleName}.repository;

#foreach($i in $imports)
import $i;
#end
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.joinway.appx.repository.AbstractDaoRepository;
import com.joinway.${domainModuleName}.bean.domain.${DomainName};
import com.joinway.${mapperModuleName}.mapper.${DomainName}Mapper;

@Repository
public class ${DomainName}Repository extends AbstractDaoRepository {

	private final static Logger log = LoggerFactory.getLogger(${DomainName}Repository.class);
	
	@Autowired ${DomainName}Mapper mapper;
#set($params="")
#set($params2="")
#foreach($field in $fields)
	#if(${field.type} == "Date")
		#if(${field.condition} == "like")
			#set($params="${params}${field.type} from${field.uname}, ${field.type} to${field.uname}")
			#set($params2="${params2}formatDate(from${field.uname}), formatDate(to${field.uname})")
		#else
			#set($params="${params}${field.type} ${field.name}")
			#set($params2="${params2}formatDate(${field.name})")
		#end	## condition
	#else
		#set($params="${params}${field.type} ${field.name}")
		#set($params2="${params2}trimToNull(${field.name})")
	#end	## date type
	#if($velocityCount != $fields.size())
		#set($params="${params}, ")
		#set($params2="${params2}, ")
	#end
#end	## foreach

	List<${DomainName}> find${DomainName}s($params){
		return mapper.select${DomainName}($params2);
	}
	
	${DomainName} find${DomainName}($params){
		List<${DomainName}> records = mapper.select${DomainName}($params2);
		return getFirst(records);
	}
	
}
